package web

//
//import (
//	"booksmart/book/config"
//	"booksmart/book/internal/repository"
//	"booksmart/book/internal/repository/cache"
//	"booksmart/book/internal/repository/dao"
//	"booksmart/book/internal/service"
//	"booksmart/book/internal/service/sms/memery"
//	"booksmart/book/internal/web/middleware"
//	"github.com/gin-contrib/cors"
//	"github.com/gin-contrib/sessions"
//	"github.com/gin-contrib/sessions/redis"
//	"github.com/gin-gonic/gin"
//	redis2 "github.com/redis/go-redis/v9"
//	"gorm.io/driver/postgres"
//	"gorm.io/gorm"
//	"strings"
//	"time"
//)
//
//func RegisterRoute() *gin.Engine {
//	server := gin.Default()
//	server.Use(cors.New(cors.Config{
//		//AllowOrigins:     []string{"https://foo.com"},
//		//AllowMethods:     []string{"PUT", "PATCH"},
//		AllowHeaders: []string{"Origin", "Content-Type"},
//		//ExposeHeaders:    []string{"Content-Length"},
//		AllowCredentials: true,
//		AllowOriginFunc: func(origin string) bool {
//			if strings.Contains(origin, "localhost") {
//				return true
//			}
//			return strings.Contains(origin, "sensetime.com")
//		},
//		MaxAge: 12 * time.Hour,
//	}))
//	//store := cookie.NewStore([]byte("secret"))
//	newStore, err := redis.NewStore(16, "tcp", config.Config.Redis.Addr, "",
//		[]byte("secret"))
//	if err != nil {
//		panic(err)
//	}
//	server.Use(sessions.Sessions("mysession", newStore))
//	loginMiddleware := middleware.NewLoginMiddleware()
//	loginMiddleware.SetPath("/users/login")
//	loginMiddleware.SetPath("/users/singUp")
//	server.Use(middleware.NewLoginMiddleware().SetPath("/users/login").SetPath("/users/singUp").Build())
//	registerUserRoute(server)
//	return server
//}
//
//func registerUserRoute(server *gin.Engine) {
//	dsn := config.Config.DB.DSN
//	db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
//	if err != nil {
//		panic(err)
//	}
//	dao := dao.NewUserDao(db)
//	client := redis2.NewClient(&redis2.Options{
//		Addr: config.Config.Redis.Addr,
//	})
//	userCache := cache.NewUserCache(client)
//	repo := repository.NewUserRepository(dao, userCache)
//	svc := service.NewUserService(repo)
//	codeCache := cache.NewCodeCache(client)
//	codeRepo := repository.NewCodeRepository(codeCache)
//	smsSvc := memery.NewService()
//	codeSvc := service.NewCodeService(codeRepo, smsSvc)
//	u := NewUserHandler(svc, codeSvc)
//	group := server.Group("users")
//	group.POST("/login", u.Login)
//	group.POST("/edit", u.Edit)
//	group.POST("/profile", u.Profile)
//	group.POST("/singUp", u.SingUp)
//}
